/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ChateoController;

import java.net.InetAddress;
import java.util.ArrayList;

/**
 *
 * @author adrian
 * @author olga
 */
public class User {
    private InetAddress addr;
    private String login;
    private boolean loggedIn;
    private ArrayList<ChatMessage> messages=new ArrayList<ChatMessage>();
  
    
    public User(InetAddress addr , String login){
        this.addr=addr;
        this.login=login;
        loggedIn=false;
    
    }
    
    public User(InetAddress addr1, String login1, boolean state){
        this.addr=addr1;
        this.login=login1;
        this.loggedIn=state;
    }


    public InetAddress getAddr() {
        return addr;
    }

    public String getLogin() {
        return login;
    }

    public boolean isLoggedIn(){
        return loggedIn;
    }

    public void setAddr(InetAddress addr) {
        this.addr = addr;
    }

    public void setLogin(String login) {
        this.login = login;
    }
    
    public void setLoggingState(boolean loggedIn){
        this.loggedIn=loggedIn;
    }
    
    
    public boolean equals(User user){
        boolean bool=false;
        if((this.getLogin().equals(user.getLogin())) && (this.getAddr().equals(user.getAddr())) && (user.isLoggedIn()==this.isLoggedIn()))
        return true;
        else
            return false;
    }
    
    public void addMessage(ChatMessage message){
        messages.add(message);
        
    }
    
    public String getMessages(){
        int nbMessages = messages.size();
        int currentMessage = 0;
        String fullChat="";
        for (currentMessage=0;currentMessage<nbMessages;currentMessage++){
            fullChat=(fullChat+"\n"+messages.get(currentMessage).toString());
        }
        return fullChat;
    }
    
    @Override
    public String toString(){
        String out="";
         if (Controller.DebugMode()){
            out = (" login "+login+"("+addr+") STATE :"+loggedIn);
        }
        else
        {
            out = (login);
        }
        return out;
        
    }
    
}
